package avicit.im.lantop.basic.useconfig.service.impl;

import avicit.im.lantop.basic.useconfig.domain.LantopHighSet;
import avicit.im.lantop.basic.useconfig.domain.LantopUseSet;
import avicit.im.lantop.basic.useconfig.service.UseConfigService;
import avicit.platform6.api.syslookup.dto.SysLookupSimpleVo;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.commons.utils.RequestUtil;
import avicit.platform6.core.domain.BeanBase;
import avicit.platform6.core.exception.DaoException;
import avicit.platform6.core.jdbc.JdbcAvicit;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.core.service.ServiceBase;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * <p>金航数码科技有限责任公司</p>
 * <p>作者：胡光昌</p>
 * <p>邮箱：huguangc@avicit.com</p>
 * <p>创建时间： 2014-10-16 下午6:22:59 </p>
 * <p>类说明：利用配置模块的接口实现类</p>
 * <p>修改记录： </p>
 */
@Service
@SuppressWarnings("unchecked")
public class UseConfigServiceImpl extends ServiceBase implements UseConfigService {

	@Autowired
	private JdbcAvicit jdbcAvicit;

	@Autowired
	private HttpServletRequest request;


	@Override
	public String createArchivalMessage(String sysId, String orgId, String deptId, String useType, String defaultUseDays, String defaultBorrowDays, String defaultUrgeDays,String appointmentArsDays) {
		Map<String, Object> maps = new HashMap<>();
		String id = ComUtil.getId();
		String lastUpdateIp = RequestUtil.getClientIp(request);
		String name = SessionHelper.getLoginSysUserId(request);
		// 判断管理员如果没有登录，返回保存失败
		if(name==null||name.equals("")){
			return "0";
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("INSERT INTO LANTOP_HIGH_SET ");
		sbSql.append("(ID , ORG_ID , DEPT_ID , SYS_ID , USE_TYPE, \n");
		sbSql.append("  USE_DAYS , BORROW_DAYS , REMINDER_DAYS , APPRAISAL_DAYS ,CREATED_BY , CREATION_DATE , LAST_UPDATED_BY ,\n");
		sbSql.append("  LAST_UPDATE_DATE , LAST_UPDATE_IP , VERSION)");
		sbSql.append("VALUES ( ");
		sbSql.append("'");
		sbSql.append(id);
		sbSql.append("','");
		sbSql.append(orgId);
		sbSql.append("','");
		sbSql.append(deptId);
		sbSql.append("','");
		sbSql.append(sysId);
		sbSql.append("','");
		sbSql.append(useType);
		sbSql.append("','");
		sbSql.append(defaultUseDays);
		sbSql.append("','");
		sbSql.append(defaultBorrowDays);
		sbSql.append("','");
		sbSql.append(defaultUrgeDays);
		sbSql.append("','");
		sbSql.append(appointmentArsDays);
		sbSql.append("','");
		sbSql.append(name);
		sbSql.append("',to_date('");
		sbSql.append(ComUtil.Date2String(new Date()));
		sbSql.append("','yyyy-mm-dd'),'");
		sbSql.append(name);
		sbSql.append("',to_date('");
		sbSql.append(ComUtil.Date2String(new Date()));
		sbSql.append("','yyyy-mm-dd'),'");
		sbSql.append(lastUpdateIp);
		sbSql.append("','0')");
		String sql = sbSql.toString().replace("null", "");
		this.jdbcAvicit.getJdbcTemplate().execute(sql);
		maps.put("success", 1);
		SysLogUtil.log("利用配置模块", "插入利用配置记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		return "1";
	}

	/**
	 * 删除本全宗下配置数据信息
	 * @param sysId
	 * @param deptId
	 * @param orgId
	 */
	@Override
	public void deleteUseData(String sysId, String deptId, String orgId) {
		StringBuffer deSql = new StringBuffer();
		deSql.append("DELETE FROM LANTOP_HIGH_SET WHERE SYS_ID='"+sysId+"' AND DEPT_ID ='"+deptId+"' AND ORG_ID='"+orgId+"'");
		this.jdbc.getJdbcTemplate().execute(deSql.toString());
	}

	@Override
	public void delete(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void insert(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	/**
	 * 初始化系统业务参数配置信息
	 * @param sysId
	 * @param deptId
	 * @param orgId
	 * @return
	 */
	@Override
	public List<Map<String, Object>>  selectUserConfig(String sysId, String deptId, String orgId) {
		List<Map<String, Object>> mapList = new ArrayList<>();
		// 判断当前全宗下是否有无数据
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT count(ID) FROM LANTOP_HIGH_SET WHERE ORG_ID = '"+orgId+"'");
		List<Map<String,Object>> count = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		int rowCount = Integer.parseInt(count.get(0).get("count(ID)").toString());
		if(rowCount>0){ // 有数据的情况下，进行展示数据，并且返回更新标识
			sbSql = new StringBuffer();
			sbSql.append("SELECT ID,USE_TYPE,USE_DAYS,BORROW_DAYS,REMINDER_DAYS,APPRAISAL_DAYS");
			sbSql.append(" FROM LANTOP_HIGH_SET WHERE ORG_ID = '"+orgId+"' AND USE_TYPE IN ('JD','XZ','DY','LL','JY','LLWSY','XZWSY','ZZYJ')");
			List<Map<String,Object>> listData = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
			Map<String,Object> param = new HashMap<>();
			for (Map<String,Object> maps: listData) {
				if(maps.get("USE_TYPE").equals("JD")){ // 类型为鉴定，获取鉴定天数
					String appraisalDays = (maps.get("APPRAISAL_DAYS")==null)?"":maps.get("APPRAISAL_DAYS").toString();
					param.put("appointmentArsDays",appraisalDays);
				}
				if(maps.get("USE_TYPE").equals("XZ")){ // 类型为下载，获取下载可利用天数和可续借天数
					String xzUseDays = (maps.get("USE_DAYS")==null)?"":maps.get("USE_DAYS").toString();
					String xzBorrowDays = (maps.get("BORROW_DAYS")==null)?"":maps.get("BORROW_DAYS").toString();
					param.put("download_defaultUseDays",xzUseDays);
					param.put("download_defaultBorrowDays",xzBorrowDays);
				}
				if(maps.get("USE_TYPE").equals("DY")){ // 类型为打印，获取打印可利用天数和可续借天数
					String dyUseDays = (maps.get("USE_DAYS")==null)?"":maps.get("USE_DAYS").toString();
					String dyBorrowDays = (maps.get("BORROW_DAYS")==null)?"":maps.get("BORROW_DAYS").toString();
					param.put("printing_defaultUseDays",dyUseDays);
					param.put("printing_defaultBorrowDays",dyBorrowDays);
				}
				if(maps.get("USE_TYPE").equals("LL")){ // 类型为浏览，获取浏览可利用天数和可续借天数
					String llUseDays = (maps.get("USE_DAYS")==null)?"":maps.get("USE_DAYS").toString();
					String llBorrowDays = (maps.get("BORROW_DAYS")==null)?"":maps.get("BORROW_DAYS").toString();
					param.put("browse_defaultUseDays",llUseDays);
					param.put("browse_defaultBorrowDays",llBorrowDays);
				}
				if(maps.get("USE_TYPE").equals("JY")){ // 类型为浏览，获取浏览可利用天数和可续借天数,提前催还天数
					String jyUseDays = (maps.get("USE_DAYS")==null)?"":maps.get("USE_DAYS").toString();
					String jyBorrowDays = (maps.get("BORROW_DAYS")==null)?"":maps.get("BORROW_DAYS").toString();
					String jyReminderDays = (maps.get("REMINDER_DAYS")==null)?"":maps.get("REMINDER_DAYS").toString();
					param.put("borrowing_defaultUseDays",jyUseDays);
					param.put("borrowing_defaultBorrowDays",jyBorrowDays);
					param.put("borrowing_defaultUrgeDays",jyReminderDays);
				}
				if(maps.get("USE_TYPE").equals("LLWSY")){ // 类型为浏览(无水印)，获取浏览可利用天数和可续借天数,提前催还天数
					String jyUseDays = (maps.get("USE_DAYS")==null)?"":maps.get("USE_DAYS").toString();
					String jyBorrowDays = (maps.get("BORROW_DAYS")==null)?"":maps.get("BORROW_DAYS").toString();
					String jyReminderDays = (maps.get("REMINDER_DAYS")==null)?"":maps.get("REMINDER_DAYS").toString();
					param.put("borrowingNoWatermark_defaultUseDays",jyUseDays);
					param.put("borrowingNoWatermark_defaultBorrowDays",jyBorrowDays);
					param.put("borrowingNoWatermark_defaultUrgeDays",jyReminderDays);
				}
				if(maps.get("USE_TYPE").equals("XZWSY")){ // 类型为下载(无水印)，获取浏览可利用天数和可续借天数,提前催还天数
					String jyUseDays = (maps.get("USE_DAYS")==null)?"":maps.get("USE_DAYS").toString();
					String jyBorrowDays = (maps.get("BORROW_DAYS")==null)?"":maps.get("BORROW_DAYS").toString();
					String jyReminderDays = (maps.get("REMINDER_DAYS")==null)?"":maps.get("REMINDER_DAYS").toString();
					param.put("downloadNoWatermark_defaultUseDays",jyUseDays);
					param.put("downloadNoWatermark_defaultBorrowDays",jyBorrowDays);
					param.put("downloadNoWatermark_defaultUrgeDays",jyReminderDays);
				}
				if(maps.get("USE_TYPE").equals("ZZYJ")){ // 类型为纸质原件	，获取浏览可利用天数和可续借天数,提前催还天数
					String jyUseDays = (maps.get("USE_DAYS")==null)?"":maps.get("USE_DAYS").toString();
					String jyBorrowDays = (maps.get("BORROW_DAYS")==null)?"":maps.get("BORROW_DAYS").toString();
					String jyReminderDays = (maps.get("REMINDER_DAYS")==null)?"":maps.get("REMINDER_DAYS").toString();
					param.put("downloadPaper_defaultUseDays",jyUseDays);
					param.put("downloadPaper_defaultBorrowDays",jyBorrowDays);
					param.put("downloadPaper_defaultUrgeDays",jyReminderDays);
				}
			}
			param.put("flag","1");
			mapList.add(param); // 添加更新标识
		}else{ // 没有数据的情况下，默认所有天数10，返回新增标识
			Map<String,Object> params = new HashMap<>();
			params.put("flag","2");
			mapList.add(params); // 添加新增标识
		}
		return mapList;
	}

	@Override
	public void doInitHighSetDatas(Map<String, Object> param) {
		String orgId = (String) param.get("orgId");
		String sysId = (String) param.get("sysId");
		String deptId = (String) param.get("deptId");
		//判断当前组织是否有数据,如果没有,则初始化数据
		
		Collection<SysLookupSimpleVo> secretLevelList = (Collection<SysLookupSimpleVo>) param.get("secretList");
		Iterator<SysLookupSimpleVo> secretIt = secretLevelList.iterator();
		String secretHql = "";
		while (secretIt.hasNext()) {
			SysLookupSimpleVo secret = secretIt.next();
			secretHql += "'" + secret.getLookupCode() + "',";
		}
		secretHql = secretHql.substring(0, secretHql.length() - 1);
		Collection<SysLookupSimpleVo> lantopUseTypeList = (Collection<SysLookupSimpleVo>) param.get("useTypeList");
		Iterator<SysLookupSimpleVo> useTypeIt = lantopUseTypeList.iterator();
		String useTypeHql = "";
		while (useTypeIt.hasNext()) {
			SysLookupSimpleVo useType = useTypeIt.next();
			useTypeHql += "'" + useType.getLookupCode() + "',";
		}
		useTypeHql = useTypeHql.substring(0, useTypeHql.length() - 1);
		String hql = "from LantopHighSet where orgId = '" + orgId + "' and secretCode in (" + secretHql + ") and useType in (" + useTypeHql + ")";
		List<LantopHighSet> lhsList = this.hibernateDao.find(hql);
		int count = secretLevelList.size() * lantopUseTypeList.size();
		if (lhsList.size() < count) {
			Iterator<SysLookupSimpleVo> secretList = secretLevelList.iterator();
			while (secretList.hasNext()) {
				SysLookupSimpleVo secret = secretList.next();
				Iterator<SysLookupSimpleVo> useTypeList = lantopUseTypeList.iterator();
				while (useTypeList.hasNext()) {
					SysLookupSimpleVo useType = useTypeList.next();
					boolean isHave = false;
					for (int i = 0; i < lhsList.size(); i++) {
						LantopHighSet lhs = lhsList.get(i);
						if (secret.getLookupCode().equals(lhs.getSecretCode()) && useType.getLookupCode().equals(lhs.getUseType())) {
							isHave = true;
							continue;
						}
					}
					if (isHave == false) {
						LantopHighSet lhs = new LantopHighSet();
						lhs.setSecretCode(secret.getLookupCode());
						lhs.setUseType(useType.getLookupCode());
						lhs.setSysId(sysId);
						lhs.setOrgId(orgId);
						lhs.setDeptId(deptId);
						PojoUtil.setSysProperties(lhs, OpType.insert);
						this.saveHighSet(lhs);
					}
				}
			}
		}
	}

	/**
	 * 获取高级设置的信息
	 * @author 胡光昌
	 * @param page
	 * @param param void
	 * @throws
	 */
	@Override
	public void findSetInfo(Page<Map<String, Object>> page, Map<String, Object> param) {
		String orgId = (String) param.get("orgId");
		Collection<SysLookupSimpleVo> useTypeList = (Collection<SysLookupSimpleVo>) param.get("useTypeList");
		Collection<SysLookupSimpleVo> secretList = (Collection<SysLookupSimpleVo>) param.get("secretList");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("select ID,\n");
		sbSql.append("       SECRET_CODE,\n");
		sbSql.append("       SECRET_NAME,\n");
		sbSql.append("       USE_TYPE,\n");
		sbSql.append("       USE_TYPE_NAME,\n");
		sbSql.append("       USE_DAYS,\n");
		sbSql.append("       BORROW_DAYS,\n");
		sbSql.append("       BORROW_NUM\n");
		sbSql.append("		from LANTOP_HIGH_SET_V T where T.ORG_ID = '" + orgId + "' \n");
		if (secretList.size() > 0) {
			sbSql.append(" AND SECRET_CODE IN (");
			Iterator<SysLookupSimpleVo> secretIter = secretList.iterator();
			int index = 0;
			while (secretIter.hasNext()) {
				SysLookupSimpleVo secret = secretIter.next();
				sbSql.append("'" + secret.getLookupCode() + "'");
				if (index != secretList.size() - 1) {
					sbSql.append(",");
				}
				index++;
			}
			sbSql.append(")");
		}
		if (useTypeList.size() > 0) {
			sbSql.append(" AND USE_TYPE IN (");
			Iterator<SysLookupSimpleVo> useTypeIter = useTypeList.iterator();
			int index = 0;
			while (useTypeIter.hasNext()) {
				SysLookupSimpleVo useType = useTypeIter.next();
				sbSql.append("'" + useType.getLookupCode() + "'");
				if (index != useTypeList.size() - 1) {
					sbSql.append(",");
				}
				index++;
			}
			sbSql.append(")");
		}
		sbSql.append("		ORDER BY T.SECRET_CODE ASC, T.USE_TYPE DESC");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	/**
	 * 保存高级设置数据
	 * @author 胡光昌
	 * @param lantopHighSet void
	 * @throws
	 */
	@Override
	public void saveHighSet(LantopHighSet highSet) {
		highSet.setId(ComUtil.getId());
		this.hibernateDao.save(highSet);
		SysLogUtil.log(highSet, null, OpType.insert, OpResult.success);
	}

	/**
	 * 更新高级设置数据
	 */
	@Override
	public void updateHighSet(Map<String, Object> map) {
		LantopHighSet oldBean = this.hibernateDao.get(LantopHighSet.class, map.get("ID").toString());
		this.hibernateDao.evict(oldBean);
		LantopHighSet newBean = new LantopHighSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
//		if (map.get("USE_TYPE_NAME") != null) {
//			String str = map.get("USE_TYPE_NAME").toString();
//			if (str.indexOf("借阅") != -1) {
//				str = str.replace("借阅", "JY");
//			}
//			if (str.indexOf("查阅") != -1) {
//				str = str.replace("查阅", "CY");
//			}
//			if (str.indexOf("下载") != -1) {
//				str = str.replace("下载", "XZ");
//			}
//			if (str.indexOf("续借") != -1) {
//				str = str.replace("续借", "XJ");
//			}
//			if (str.indexOf("浏览") != -1) {
//				str = str.replace("浏览", "LL");
//			}
//			if (str.indexOf("打印") != -1) {
//				str = str.replace("打印", "DY");
//			}
//			if (str.indexOf("复印") != -1) {
//				str = str.replace("复印", "FY");
//			}
//			if (str.indexOf("扫描") != -1) {
//				str = str.replace("扫描", "SM");
//			}
//			newBean.setUseType(str.toString());
//		}
		if (map.get("USE_TYPE") != null) {
			String str = map.get("USE_TYPE").toString();
			newBean.setUseType(str.toString());
		}
		if (map.get("USE_DAYS") != null && !"".equals(map.get("USE_DAYS"))) {
			int useDays = Integer.valueOf(map.get("USE_DAYS").toString());
			newBean.setUseDays(useDays);
		}
		if (map.get("BORROW_DAYS") != null && !"".equals(map.get("BORROW_DAYS"))) {
			int borrowDays = Integer.valueOf(map.get("BORROW_DAYS").toString());
			newBean.setBorrowDays(borrowDays);
		}
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	/**
	 * 校验高级设置数据重复
	 */
	@Override
	public int getCount(Map<String, Object> map) {
		String str = "";
		if (map.get("USE_TYPE_NAME") != null) {
			str = map.get("USE_TYPE_NAME").toString();
			if (str.indexOf("借阅") != -1) {
				str = str.replace("借阅", "JY");
			}
			if (str.indexOf("查阅") != -1) {
				str = str.replace("查阅", "CY");
			}
			if (str.indexOf("下载") != -1) {
				str = str.replace("下载", "XZ");
			}
			if (str.indexOf("续借") != -1) {
				str = str.replace("续借", "XJ");
			}
			if (str.indexOf("浏览") != -1) {
				str = str.replace("浏览", "LL");
			}
		}
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT ID FROM LANTOP_HIGH_SET WHERE SECRET_CODE = '");
		sql.append(map.get("SECRET_CODE").toString());
		sql.append("' AND USE_TYPE = '");
		sql.append(str);
		sql.append("'");
		if (map.get("USE_DAYS") != null) {
			sql.append(" AND USE_DAYS = '");
			sql.append(map.get("USE_DAYS").toString());
			sql.append("'");
		}
		if (map.get("BORROW_DAYS") != null) {
			sql.append(" AND BORROW_DAYS = '");
			sql.append(map.get("BORROW_DAYS").toString());
			sql.append("'");
		}
		if (map.get("BORROW_NUM") != null) {
			sql.append("  AND BORROW_NUM = '");
			sql.append(map.get("BORROW_NUM").toString());
			sql.append("'");
		}
		if (map.get("ID") != null) {
			sql.append(" AND ID != '" + map.get("ID").toString() + "'");
		}
		List<?> list = jdbcAvicit.getJdbcTemplate().queryForList(sql.toString());
		return list.size();
	}

	/**
	 * 获取配置的数据
	 * @param currentOrgId
	 * @param currentDeptId
	 * @return Map<String,Object>
	 * @throws
	 */
	@Override
	public Map<String, String> findConfig(String orgId, String deptId) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT * FROM LANTOP_USE_SET  WHERE ORG_ID='");
		sql.append(orgId);
		sql.append("'");
		List<Map<String, Object>> list = jdbcAvicit.getJdbcTemplate().queryForList(sql.toString());
		Map<String, String> map = new HashMap<String, String>();
		String keyWord = "";
		String keyValue = "";
		for (int i = 0; i < list.size(); i++) {
			keyWord =String.valueOf(list.get(i).get("KEY_WORD"));
			keyValue = String.valueOf(list.get(i).get("KEY_VALUE"));
			if(null == keyValue || "null".equals(keyValue)){
				keyValue = "";
			}
			map.put(keyWord, keyValue);
		}
		return map;
	}

	/**
	 * 获取利用配置关键字的id
	 */
	@Override
	public String findIdByKeyWord(String keyWord) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT ID FROM LANTOP_USE_SET WHERE KEY_WORD= '");
		sql.append(keyWord);
		sql.append("'");
		String id = "";
		List<Map<String, Object>> idList = new ArrayList<Map<String, Object>>();
		idList = jdbcAvicit.queryForMap(sql.toString(), null);
		if (idList != null && idList.size() > 0) {
			Map<String, Object> map = new HashMap<String, Object>();
			map = idList.get(0);
			id = String.valueOf(map.get("ID").toString());
		}
		return id;
	}
	
	/**
	 * 获取利用配置关键字的id
	 */
	@Override
	public String findIdByKeyWordForOrgId(String keyWord, String orgId) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT ID FROM LANTOP_USE_SET WHERE KEY_WORD= '");
		sql.append(keyWord);
		sql.append("' AND ORG_ID = '" + orgId + "'");
		String id = "";
		List<Map<String, Object>> idList = new ArrayList<Map<String, Object>>();
		idList = jdbcAvicit.queryForMap(sql.toString(), null);
		if (idList != null && idList.size() > 0) {
			Map<String, Object> map = new HashMap<String, Object>();
			map = idList.get(0);
			id = String.valueOf(map.get("ID").toString());
		}
		return id;
	}

	// 默认利用天数
	@Override
	public void updatedefaultUseDaysKeyValue(Map<String, String> map, String defaultUseDaysid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, defaultUseDaysid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("DEFAULT_USE_DAYS"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 默认续借天数
	@Override
	public void updatedefaultBorrowDaysKeyValue(Map<String, String> map, String defaultBorrowDaysid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, defaultBorrowDaysid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("DEFAULT_BORROW_DAYS"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 默认续借次数
	@Override
	public void updatedefaultBorrowNumKeyValue(Map<String, String> map, String defaultBorrowNumid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, defaultBorrowNumid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("DEFAULT_BORROW_NUM"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 借还预警天数
	@Override
	public void updateborrowForcastDaysKeyValue(Map<String, String> map, String borrowForcastDaysid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, borrowForcastDaysid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("BORROW_FORCAST_DAYS"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 默认借阅类型（1：原件、2：复制件）
	@Override
	public void updatededefaultBorrowTypeKeyValue(String defaultBorrowTypeid, String defaultBorrowTypeValue) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, defaultBorrowTypeid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(defaultBorrowTypeValue);
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 预约队列数量
	@Override
	public void updateforcastQueueNumKeyValue(Map<String, String> map, String forcastQueueNumid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, forcastQueueNumid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("FORCAST_QUEUE_NUM"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 预约超时时间
	@Override
	public void updateforcastOvertimeKeyValue(Map<String, String> map, String forcastOvertimeid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, forcastOvertimeid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("FORCAST_OVERTIME"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 个人消息最大记录数
	@Override
	public void updatepsnMsgMaxRcdsKeyValue(Map<String, String> map, String psnMsgMaxRcdsid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, psnMsgMaxRcdsid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("PSN_MSG_MAX_RCDS"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 发件服务器
	@Override
	public void updatesendSvrKeyValue(Map<String, String> map, String sendSvrid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, sendSvrid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("SEND_SVR"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 发件端口
	@Override
	public void updatesendPortKeyValue(Map<String, String> map, String sendPortid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, sendPortid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("SEND_PORT"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 收件服务器
	@Override
	public void updatercvSvrKeyValue(Map<String, String> map, String rcvSvrid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, rcvSvrid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("RCV_SVR"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 收件端口
	@Override
	public void updatercvPortKeyValue(Map<String, String> map, String rcvPortid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, rcvPortid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("RCV_PORT"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 更新高级设置为启动
	@Override
	public void updateValueStart(String isHighSetid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, isHighSetid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue("1");
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 更新高级设置为未启动
	@Override
	public void updateValueEnd(String isHighSetid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, isHighSetid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue("2");
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 修改启动预约借阅为启动
	@Override
	public void updateisBorrowForcastKeyValueStart(String isBorrowForcastid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, isBorrowForcastid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue("1");
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 修改启动预约借阅为未启动
	@Override
	public void updateisBorrowForcastKeyValueEnd(String isBorrowForcastid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, isBorrowForcastid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue("2");
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);

	}

	// 修改邮件通知为启动
	@Override
	public void updateisEmailKeyValueStart(String isEmailid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, isEmailid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue("1");
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);

	}

	// 修改邮件通知为未启动
	@Override
	public void updateisEmailKeyValueEnd(String isEmailid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, isEmailid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue("2");
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);

	}

	// 修改发件人账户
	@Override
	public void updateSendEmailCountKeyValue(Map<String, String> map, String sendEmailCountid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, sendEmailCountid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("SEND_EMAIL_COUNT"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	// 修改发件人密码
	@Override
	public void updatePasswordKeyValue(Map<String, String> map, String passwordid) {
		LantopUseSet oldBean = this.hibernateDao.get(LantopUseSet.class, passwordid);
		this.hibernateDao.evict(oldBean);
		LantopUseSet newBean = new LantopUseSet();
		PojoUtil.copyProperties(newBean, oldBean, true);
		newBean.setKeyValue(map.get("PASSWORD"));
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	/**
	 * 获取催还预警天数
	 * @author 郭亮
	 * @return
	 * @throws Exception String
	 */
	@Override
	public String getBorrowForcastDays() throws Exception {
		String borrowForcastDays = "";
		String sql = "SELECT T.KEY_VALUE FROM LANTOP_USE_SET T WHERE T.KEY_WORD = 'BORROW_FORCAST_DAYS'";
		List<String> list = this.hibernateDao.findBySQL(sql);
		if (list.size() > 0) {
			borrowForcastDays = list.get(0);
		}
		return borrowForcastDays;
	}

}
